package com.sskj.gcc.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.gcc.ui.activity.SlideMineActivity;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.UserInfo;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;

public class SlideMineActivityPresenter extends BasePresenter<SlideMineActivity> {
    public void requestUserInfo() {
        OkGo.<HttpData<UserInfo>>get(HttpConfig.BASE_URL + HttpConfig.GET_USER_INFO)
                .execute(new JsonCallBack<HttpData<UserInfo>>() {
                    @Override
                    public void onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getCode() == 200) {
                            mView.updateStatus(httpData.getData());
                        } else {
                            mView.updateStatus(null);

                        }
                    }

                    @Override
                    public void onError(Response<HttpData<UserInfo>> response) {
                        super.onError(response);
                        mView.updateStatus(null);
                    }
                });
    }
    public void requestRelieveBusiness() {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.RELIEVE_BUSINESS)
                .execute(new JsonCallBack<HttpData<Object>>() {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
//                        alertDialog.dismiss();
                        if (response.body().getCode() == 200) {
                            mView.onRelieveBusinessSuccess();
                            ToastUtil.showShort(response.message());
                        }
                    }

                    @Override
                    public void onError(Response<HttpData<Object>> response) {
                        super.onError(response);
//                        alertDialog.dismiss();
                    }
                });
    }

    public void signIn() {
        httpService.toSignIn().execute(new JsonCallBack<HttpData<List<String>>>() {
            @Override
            public void onSuccess(Response<HttpData<List<String>>> response) {
                HttpData httpData = response.body();
                if (httpData.getCode() == HttpConfig.OK) {
                    if (response.body().getData() != null && response.body().getData().size() > 0) {
                        ToastUtil.showShort(App.INSTANCE.getString(com.sskj.gocoin.R.string.sing_success) + response.body().getData().get(0) + App.INSTANCE.getString(com.sskj.gocoin.R.string.fabimineJavaCommonDetail8));
                    }
                    mView.signInSuccess();
                }
            }
        });

    }

}
